package com.ruoyi.exam.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruoyi.exam.domain.enums.QuestionTypeEnum;
import com.ruoyi.exam.utils.ExamUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 题目表
 * </p>
 *
 * @author FSD
 * @since 2024-02-19
 */
@Getter
@Setter
@TableName("t_question")
@ApiModel(value = "Question对象", description = "题目表")
public class Question implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("1.单选题 2.多选题 3.判断题 4.填空题 5.简答题")
    private Integer questionType;

    @ApiModelProperty("学科")
    private Integer subjectId;

    @ApiModelProperty("题目总分(千分制)")
    private Integer score;

    @ApiModelProperty("级别")
    private Integer gradeLevel;

    @ApiModelProperty("题目难度")
    private Integer difficult;

    @ApiModelProperty("正确答案")
    private String correct;

    @ApiModelProperty("题目 填空、 题干、解析、答案等信息")
    private Integer infoTextContentId;

    @ApiModelProperty("创建人")
    private Integer createUser;

    @ApiModelProperty("1.正常 0删除")
    private Integer status;

    @ApiModelProperty("创建时间")
    private Date createTime;

    private Boolean deleted;

    public void setCorrectFromVM(String correct, List<String> correctArray) {
        int qType = this.getQuestionType();
        if (qType == QuestionTypeEnum.MultipleChoice.getCode()) {
            String correctJoin = ExamUtil.contentToString(correctArray);
            this.setCorrect(correctJoin);
        } else {
            this.setCorrect(correct);
        }
    }

}
